#include <AST/ExprAST.hpp>
#include <AST/expr/operator/BinaryOpAST.hpp>

Expr *Expr::sequenceOf(ExprVector &&exprs) {
    return sequenceOf(exprs);
}


Expr *Expr::sequenceOf(ExprVector &exprs) {
    while (!exprs.empty() && exprs.back() == nullptr) exprs.pop_back();
    while (!exprs.empty() && exprs.front() == nullptr) exprs.erase(exprs.begin());
    if (exprs.size() == 0) return nullptr;
    if (exprs.size() == 1) return exprs[0];
    Expr *last = exprs[0];
    for (unsigned int i = 1; i < exprs.size(); ++i) {
        last = new BinaryOp(OpType::Semi, last, exprs[i]);
    }
    return last;
}
